import { configureStore } from '@reduxjs/toolkit'
import BooksSlice from "./modules/booksSlice.ts"
import ShoppingCarSlice from "./modules/shoppingCarSlice.ts"
import UserInfoSlice from "./privates/userInfoSlice.ts"
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux';

export type RootState = ReturnType<typeof store.getState>
type AppDispatch = typeof store.dispatch

// 这是一个用于修改或增加仓库数据的函数
export const useAppDispatch = ()=>useDispatch<AppDispatch>();

// 这是一个hook 专门用于获取仓库数据
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector


export const store = configureStore({
    reducer:{
        book : BooksSlice,
        shoppingcar:ShoppingCarSlice,
        userInfo:UserInfoSlice
    },
    middleware:getDefaultMiddleware => getDefaultMiddleware({
        //关闭redux序列化检测
        serializableCheck:false
    })
})

